package compare;

public class ComparableDome {
    public static void main(String[] args) {
        Person p1 = new Person(1,2,3,4);
        Person p2 = new Person(3,6,4,4);

        int tmp = p1.compareTo(p2);
        if(tmp > 0){
            System.out.println(p1 + " 大于 " + p2);
        }else if(tmp < 0){
            System.out.println(p1 + " 小于 " + p2);
        }else{
            System.out.println(p1 + " 等于 " + p2);
        }

        //所有实现了 Comparable 接口的类，该类型的变量都可以使用 compareTo 方法，不论是自己写的还是 Java 自带的
        //String 也实现了 Comparable 接口,所以 String 类型的变量也可以用 compareTo 进行比较
        String s1 = "hello";
        String s2 = "world";

        int cmp = s1.compareTo(s2);
        if(cmp > 0){
            System.out.println(s1 + "大于" + s2);
        }else if(cmp < 0){
            System.out.println(s1 + "小于" + s2);
        }else{
            System.out.println(s1 + "等于" + s2);
        }
    }
}
